package com.yupi.springbootinit.api;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.Map;

public class BIapi {
    public static void main(String[] args) {

        String url = "https://api.openai.com/v1/chat/completions";  // 接口地址
        Map<String, Object> hashMap =new HashMap<>();
        hashMap.put("message", "用户的消息，请帮我分析");
        String json= JSONUtil.toJsonStr(hashMap);
        String result = HttpRequest.post(url)
                .header("Authorization", "Bearer 替换可用的key")
                .body(json)
                .execute()
                .body();
        //最终返回结果
//        "id": "chatcmpl-7BjgZJ9hZ4nGw7X4pXK5vLdY3p9O",
//        "object": "chat.completion",
//        "created": 1706365290,
//        "choices": [{
//            "index": 0,
//            "message": {
//                "role": "assistant",
//                "content": "\n\nHello! How can I help you today?"
//            },
//            "finish_reason": "stop"
//        }],
//        "usage": {
//            "prompt_tokens": 9,
//            "completion_tokens": 17,
//            "total_tokens": 26
//        }

    }
}
